<?php

/**
 * 日志工具类
 */

namespace custom;


use think\facade\Request;

class Log {

    protected static $request = null;

    /**
     * 写入日志文件
     * @param $data
     * @param string $file
     */
    public static function write($data, $file = 'default.log') {
        $data = date('Y-m-d H:i:s') . "\t" . (is_array($data) ? json_encode($data, JSON_UNESCAPED_UNICODE | JSON_UNESCAPED_SLASHES) : $data) . "\r\n\r\n";
        $module = Request::module();
        if (empty($module))
            $module = '_';

        $filename = config('global.log_dir') . $module . "/$file";
        @file_put_autodir($filename, $data, FILE_APPEND | LOCK_EX);
    }


}
